﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using nSL.Config;
using nSL.Libs;
using System.IO;

namespace nSL.UC
{
    /// <summary>
    /// Interaction logic for PDFViewer.xaml
    /// </summary>
    public partial class PDFViewer : UserControl
    {
        public PDFViewer()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(PDFViewer_Loaded);
            //FileHelper.pdfFromURL(_pdfFile, textBox2.Text.Trim());
        }

        void PDFViewer_Loaded(object sender, RoutedEventArgs e)
        {
            _chkPath = Common.CURRENT_APP_PATH + "\\Temp\\" + EncryptHelper.CalculateSHA1(_pdfFile) + ".pdf";
            if (File.Exists(_chkPath))
            {
                Stream fs = File.OpenRead(_chkPath);
                c1PdfViewer1.LoadDocument(fs);
            }
            else
            {
                FileHelper.pdfFromURL(_pdfFile, _chkPath);
                Stream fs = File.OpenRead(_chkPath);
                c1PdfViewer1.LoadDocument(fs);
            }
            //throw new NotImplementedException();
        }
        private string _chkPath;
        private string _pdfFile;

        public string PdfPath
        {
            get { return _pdfFile; }
            set { _pdfFile = value; }
        }

        private void back_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (Message.Confirm(cString.ID("video.stop")))
            {
                UC.Lecture lecture = new Lecture();
                lecture.LectureInfo = Common.lecture_info;
                WpfPageTransitions.PageTransition transition = new WpfPageTransitions.PageTransition();
                transition.TransitionType = WpfPageTransitions.PageTransitionType.Slide;
                transition.ShowPage(lecture);
                Window.GetWindow(this).Content = transition;
            }
        }
    }
}
